﻿using System;
using System.Reflection;
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
using RikMigrations.Providers;

namespace RikMigrations.MsBuildTask
{
    public class Migrate : Task
    {
        [Required]
        public string ConnectionString { get; set; }

        [Required]
        public string AssemblyName { get; set; }
        
        public override bool Execute()
        {
            DbProvider.DefaultConnectionString = ConnectionString;
            Assembly migrations = Assembly.LoadFrom(AssemblyName);
            MigrationManager.UpgradeMax(migrations);

            return true;
        }
    }
}
